package com.lc.base;

import com.lc.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * <p>
 * 统一返回Bean
 * </p>
 *
 * @author xjq
 * @since 2020-05-20
 */
@Data
@Accessors(chain = true)
@ApiModel("统一返回Bean")
public class ResultBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = ResultEnum.SUCCESS.getCode();

    public static final int FAIL = ResultEnum.ERROR.getCode();

    public static final String SUCCESSMSG = "处理成功";

    public static final String FAILMSG = "处理失败";

    private int code = SUCCESS;

    private String msg = "处理成功";

    private T data;

    public ResultBean() {
        super();
    }

    public ResultBean(T data) {
        super();
        this.data = data;
    }

    public ResultBean success(T data) {
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(SUCCESS);
        resultBean.setMsg(SUCCESSMSG);
        resultBean.setData(data);
        return resultBean;
    }

    public ResultBean fail(Throwable e) {
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(FAIL);
        resultBean.setMsg(FAILMSG);
        resultBean.setData(data);
        return resultBean;
    }

}
